package com.example.cp.busi;

import androidx.lifecycle.MutableLiveData;

import com.example.cp.entivity.BannerResult;
import com.example.cp.entivity.VideoResult;
import com.example.cp.mvvm.base.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class VideoRepo extends BaseRepo {
    public void getVideo(int page, int size, MutableLiveData<VideoResult> success,MutableLiveData<String> fail){
        apiService.getVideo(page,size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<VideoResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(VideoResult videoResult) {
                        success.setValue(videoResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void getBanner(MutableLiveData<BannerResult> success,MutableLiveData<String> fail){
        apiService.getBanner()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BannerResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(BannerResult bannerResult) {
                            success.setValue(bannerResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
